/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package pl.droidsonroids.gif.gifsample.slice;

import pl.droidsonroids.gif.gifsample.ResourceTable;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;

/**
 * MainAbilitySlice
 */
public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        initializeViews();
    }

    private void initializeViews() {
        Button gifElement = (Button) findComponentById(ResourceTable.Id_gif_element);
        gifElement.setClickedListener(Component -> {
            present(new GifElementSlice(), new Intent());
        });

        Button gifDecoder = (Button) findComponentById(ResourceTable.Id_gif_decoder);
        gifDecoder.setClickedListener(Component -> {
            present(new DecoderSlice(), new Intent());
        });

        Button gifTextView = (Button) findComponentById(ResourceTable.Id_gif_textView);
        gifTextView.setClickedListener(Component -> {
            present(new GifTextViewSlice(), new Intent());
        });

        Button gifAnimation = (Button) findComponentById(ResourceTable.Id_gif_animation_control);
        gifAnimation.setClickedListener(Component -> {
            present(new AnimationSlice(), new Intent());
        });

        Button gif2d = (Button) findComponentById(ResourceTable.Id_gif_2d);
        gif2d.setClickedListener(Component -> {
            present(new Gif2dSlice(), new Intent());
        });
    }
}
